package com.wr.pojos;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * Created by Administrator on 2016/10/28 0028.
 */
public class UserEntity implements Serializable {

    private String id;
    private String userName;
    private String password;
    private String mobile;
    private String createTime;
    private String updateTime;

    private String description;

    private String headImg;
    public UserEntity(String mobile,String password){
        this.mobile = mobile;
        this.password = password;
    }
    public UserEntity(){}
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    private RoleEntity roleEntity;

    public RoleEntity getRoleEntity() {
        return roleEntity;
    }

    public void setRoleEntity(RoleEntity roleEntity) {
        this.roleEntity = roleEntity;
    }

    public String getHeadImg() {
        return headImg;
    }

    public void setHeadImg(String headImg) {
        this.headImg = headImg;
    }

    /**
     * 返回一级目录
     */
    public List<PermissionEntity> getRootMenuList(){
        List<PermissionEntity> menuList = new ArrayList<>();
        if(roleEntity==null){
            return menuList;
        }
        menuList.addAll(roleEntity.getPermissionEntityList());
        Collections.sort(menuList);
        return getRootMenuList(menuList);
    }
    /**
     * 返回一级菜单
     */
    private List<PermissionEntity> getRootMenuList(List<PermissionEntity> menuList){
        List<PermissionEntity> list = new ArrayList<>();
        if(menuList != null){
            menuList.stream().filter(_menu -> _menu != null && _menu.getParentId() == 0).forEach(_menu -> {
                _menu.setUserChildList(new ArrayList<>());
                _menu.getUserChildList().addAll(getUserChildList(_menu.getId(), menuList));
                list.add(_menu);
            });
            /*for(PermissionEntity _menu : menuList){
                if(_menu != null && _menu.getParentId() == 0){
                    _menu.setUserChildList(new ArrayList<>());
                    _menu.getUserChildList().addAll(getUserChildList(_menu.getId(),menuList));
                    list.add(_menu);
                }
            }*/
        }
        return list;
    }
    /**
     * 获取子节点
     */
    private List<PermissionEntity> getUserChildList(int parentID,List<PermissionEntity> menuList){
        List<PermissionEntity> list = new ArrayList<>();
        menuList.stream().filter(_menu -> _menu != null && _menu.getParentId() == parentID).forEach(_menu -> {
            _menu.setUserChildList(new ArrayList<>());
            _menu.getUserChildList().addAll(getUserChildList(_menu.getId(), menuList));
            list.add(_menu);
        });
        /*for(PermissionEntity _menu : menuList){
            if(_menu != null &&_menu.getParentId() == parentID){
                _menu.setUserChildList(new ArrayList<>());
                _menu.getUserChildList().addAll(getUserChildList(_menu.getId(),menuList));
                list.add(_menu);
            }
        }*/
        return list;
    }
}
